--------------------------------------------------------------------------------------------------- -- Physic objects binding ---------------------------------------------------------------------------------------------------- function init(obj) if (IsInvbox(obj)) then obj:bind_object(generic_physics_binder(obj)) return end -- bind script to object only if it has logic or if visual used for xr_box local ini = obj:spawn_ini() if (ini and ini:section_exist("logic")) then obj:bind_object(generic_physics_binder(obj)) else local visual = obj:get_visual_name() if (visual == [[dynamics\box\box_metall_01]]) then obj:bind_object(generic_physics_binder(obj)) elseif (visual == [[dynamics\box\box_wood_01]]) then obj:bind_object(generic_physics_binder(obj)) elseif (visual == [[dynamics\box\box_wood_02]]) then obj:bind_object(generic_physics_binder(obj)) end end end --------------------------------------------------------------------------------------------- class "generic_physics_binder" (object_binder) function generic_physics_binder:__init(obj) super(obj) self.initialized = false self.loaded = false db.storage[obj:id()] = {} end function generic_physics_binder:reload(section) object_binder.reload(self, section) end function generic_physics_binder:reinit() object_binder.reinit(self) db.storage[self.object:id()] = db.storage[self.object:id()] or {} self.st = db.storage[self.object:id()] end function generic_physics_binder:update(delta) object_binder.update(self, delta) if not self.initialized and db.actor then self.initialized = true xr_logic.initialize_obj(self.object, self.st, self.loaded, db.actor, modules.stype_item) end if self.st.active_section ~= nil then xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "update", delta) end self.object:set_callback(callback.hit, generic_physics_binder.hit_callback, self) self.object:set_callback(callback.death, generic_physics_binder.death_callback, self) self.object:set_callback(callback.use_object, generic_physics_binder.use_callback, self) xr_sound.update(self.object:id()) end function generic_physics_binder:net_spawn(se_abstract) if not object_binder.net_spawn(self, se_abstract) then return false end db.add_obj(self.object) return true end function generic_physics_binder:net_destroy() xr_sound.stop_sounds_by_id(self.object:id()) local st = db.storage[self.object:id()] if st.active_scheme then xr_logic.issue_event(self.object, st[st.active_scheme], "net_destroy") end local on_offline_condlist = db.storage[self.object:id()] and db.storage[self.object:id()].overrides and db.storage[self.object:id()].overrides.on_offline_condlist if on_offline_condlist ~= nil then xr_logic.pick_section_from_condlist(db.actor, self.object, on_offline_condlist) end if self.particle and self.particle:playing() then self.particle:stop() end db.del_obj(self.object) self.object:set_callback(callback.hit, nil) self.object:set_callback(callback.death, nil) self.object:set_callback(callback.use_object, nil) object_binder.net_destroy(self) end function generic_physics_binder:net_save_relevant() return true end function generic_physics_binder:save(packet) object_binder.save(self, packet) set_save_marker(packet, "save", false, "physics_binder") xr_logic.save_obj(self.object, packet) set_save_marker(packet, "save", true, "physics_binder") end function generic_physics_binder:load(reader) self.loaded = true object_binder.load(self, reader) set_save_marker(reader, "load", false, "physics_binder") xr_logic.load_obj(self.object, reader) set_save_marker(reader, "load", true, "physics_binder") end function generic_physics_binder:use_callback(obj, who) if self.st.active_section then xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "use_callback", obj, who) end -- Alundaio SendScriptCallback("physic_object_on_use_callback",self.object,who) -- Alundaio end function generic_physics_binder:hit_callback(obj, amount, local_direction, who, bone_index) if self.st.ph_on_hit then xr_logic.issue_event(self.object, self.st.ph_on_hit, "hit_callback", obj, amount, local_direction, who, bone_index) end if self.st.active_section then xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "hit_callback", obj, amount, local_direction, who, bone_index) end --Alundaio SendScriptCallback("physic_object_on_hit_callback",obj, amount, local_direction, who, bone_index) --Alundaio end function generic_physics_binder:death_callback(victim, who) --utils_data.debug_write(strformat("generic_physics_binder:death_callback %s BEGIN",victim:name())) if (self.st.active_section and self.st.active_scheme) then xr_logic.issue_event(victim, self.st[self.st.active_scheme], "death_callback", victim, who) end if self.particle and self.particle:playing() then self.particle:stop() end local ini = victim:spawn_ini() if (ini and ini:section_exist("drop_box")) then if (who) then if (who:id() == AC_ID) then game_statistics.increment_statistic("boxes_smashed") elseif IsStalker(who) and who:alive() then game_statistics.increment_npc_statistic(who,"boxes_smashed") end end xr_box.get_box_manager():spawn_items(victim,who,ini) else local visual = victim:get_visual_name() local is_box = (visual == [[dynamics\box\box_metall_01]] or visual == [[dynamics\box\box_wood_01]] or visual == [[dynamics\box\box_wood_02]]) if (is_box) then if (who) then if (who:id() == AC_ID) then game_statistics.increment_statistic("boxes_smashed") elseif IsStalker(who) and who:alive() then game_statistics.increment_npc_statistic(who,"boxes_smashed") end end if ((math.random(1,100)/100) < 0.5) then xr_box.get_box_manager():spawn_items(victim,who) end end end --utils_data.debug_write(strformat("generic_physics_binder:death_callback %s END",victim:name())) end